﻿// 类装饰器：当类定义被读取时调用
function ClassDecorator(target: Function) {
    console.log("类装饰器调用");
}

// 方法装饰器：当方法定义被读取时调用
function MethodDecorator(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
    console.log("方法装饰器调用");
}

// 访问器装饰器：当访问器定义被读取时调用
function AccessorDecorator(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
    console.log("访问器装饰器调用");
}

// 属性装饰器：当属性定义被读取时调用
function PropertyDecorator(target: any, propertyKey: string) {
    console.log("属性装饰器调用");
}

// 参数装饰器：当参数定义被读取时调用
function ParameterDecorator(target: any, propertyKey: string | symbol, parameterIndex: number) {
    console.log(`参数装饰器调用，目标参数位置: ${parameterIndex}`);
}

@ClassDecorator
class MyClass {
    @PropertyDecorator
    property: string;

    constructor( param: string) {
        this.property = param;
        console.log("MyClass 构造函数调用");
    }

    @AccessorDecorator
    get accessorProperty() {
        return this.property;
    }

    @MethodDecorator
    method(@ParameterDecorator param: string) {
        console.log("方法执行");
    }
}

// 实例化 MyClass
// const myClassInstance = new MyClass("测试参数");
// console.log(myClassInstance.accessorProperty);
// myClassInstance.method("测试方法参数");
